<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/css/styles.css" rel="stylesheet" type="text/css" />
<link href="/css/common1024.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
table{word-break:break-all;}
td{overflow:hidden;word-break:break-all;}
-->
</style>
<title>web gui for Dargens</title>
<script type='text/javascript' src='/javascripts/prototype.js'></script>
<script type='text/javascript' src='/javascripts/casper/common.js'></script>
<%= javascript_include_tag :defaults %>
<script language="JavaScript" type="text/JavaScript">
function showMsg(s)
{
	switch(s)
	{
	case 'dok':
		alert('Added to downloading queue!');
		break;
	case 'dno':
		//alert('Can't downloading this file!');
		break;
	}
}

var queryed=0;
var scriptSearch=new JavaScriptExecuter();
function search(){
	var a=document.getElementById('q').value;
	var b=document.getElementById('content').checked?'1':'0';
	var c=document.getElementById('c1').checked?'commit_string':'commit_hash';

	if(a.length==0)return false;
	scriptSearch.run("http://localhost:54321/webgui/search?query="+a+"&content="+b+"&catelog="+c);
	queryed=1;
	return false;
}
var scriptDown=new JavaScriptExecuter();
function download(a)
{
	scriptDown.run("http://localhost:54321/webgui/get?query="+a);
	return false;
}

var scriptRefresh=new JavaScriptExecuter("http://localhost:54321/webgui/refresh");
var noresult=1;
function refresh_res(){
	if(queryed!=1){return;}
	if(noresult!=1){noresult--;return;}
	scriptRefresh.run();
}
/*
function myescape(src)
{
	src=escape(src);
	src=src.replace(/\+/g,"%2B");
	return src;
}*/
function dodownload(filename)
{
	//filename=myescape(filename.substring(filename.lastIndexOf('/')+1));
	window.open("http://localhost:54321/webgui/open?query="+filename);
	return false;
}
var asTips=[];
function dispres(res,dres)
{
	var RESSIZE=res.length;
	var sc="";
	if(RESSIZE!=0)
	{
		noresult=2;
		sc="<TABLE width='500px'>";
		for( var i=0;i<RESSIZE;++i)
		{
			var obj=res[i];
			var tips="<table>";
			tips+="<tr><td>Name</td><td><div style=\"overflow:hidden\">"+obj[1]+"</div></td></tr>";
			tips+="<tr><td>Sources</td><td><div style=\"overflow:hidden\">"+obj[2]+"</div></td></tr>";
			tips+="<tr><td>Max % completed</td><td><div style=\"overflow:hidden\">"+obj[3]+"</div></td></tr>";
			tips+="<tr><td>File Size</td><td><div style=\"overflow:hidden\">"+obj[4]+"</div></td></tr>";
			tips+="<tr><td>Last Seen on</td><td><div style=\"overflow:hidden\">"+obj[5]+"</div></td></tr>";
			tips+="<tr><td>File Infos</td><td><div style=\"overflow:hidden\">"+obj[6]+"</div></td></tr>";
			tips+="<tr><td>File Hash</td><td><div style=\"overflow:hidden\">"+obj[7]+"</div></td></tr>";
			tips+="</table>";
			asTips[i]=tips;
			sc+="<TR><TD><div style='overflow:hidden' onmouseover='Tip(asTips["+i+"],TITLE,\"File info\", SHADOW, true, FADEIN, 300, FADEOUT, 300, STICKY, 1, OFFSETX, -20)'>";
			switch(obj[0])
			{
			case 0:
				sc+="<A href='"+obj[7]+"' style='color:blue' onclick='return dodownload(\""+obj[7]+"\")'>"+obj[1]+"</A>";
				break;
			case 1:
				//sc+="<span style='color:yellow'>"+obj[1]+"</span>";
				sc+="<span>"+obj[1]+"</span>";
				break;
			case 2:
				sc+="<span>"+obj[1]+"</span>";
				break;
			//case 3:
			default:
				sc+="<A href='"+obj[7]+"' onclick='return download(\""+obj[7]+"\")'>"+obj[1]+"</A>";
				break;
			}
			sc+="</div></TD><TD width='72px'>"+obj[4]+"</TD></TR>";
		}
		sc+="</TABLE>";
	}
    document.getElementById("qres").innerHTML=sc;
	RESSIZE=dres.length;
	sc="";
	var sStatus=['downloading','ready','interrupted'];
	if(RESSIZE!=0)
	{
		sc="<TABLE width='500px'>";
		for( var i=0;i<RESSIZE;++i)
		{
			var obj=dres[i];
			var bOk=(obj[1]==1);
			sc+="<TR><TD><div style='overflow:hidden'> ";
			if(bOk)	sc+='<a href="'+obj[2]+"\" style='color:blue' onclick='return dodownload(\""+obj[2]+"\")'>";
			sc+=obj[0];
			if(bOk)	sc+='</a>';
			var sInt=(obj[1]==2)?'paused':'';
			sc+="</div></TD><TD>"+(bOk?'100':obj[3])+'%</TD><TD>'+sStatus[obj[1]]+"</TD></TR>";
		}
		sc+="</TABLE>";
	}
    document.getElementById("dres").innerHTML=sc;
}
var scriptadddir=new JavaScriptExecuter("http://localhost:54321/webgui/adddir");
function adddir()
{
	scriptadddir.run();
	return false;
}
var peobj=null;
function wload()
{
	if(document.getElementById('q').value.length>0) search();
	peobj=new PeriodicalExecuter(function() {refresh_res();},3);
}
</script>
<script>var queryed=0;</script>
</head>

<body onload='wload()'>
<script type='text/javascript' src='/javascripts/tooltips/wz_tooltip.js'></script>
    <form onsubmit='return search();' action='post'>
<table algin=left style="left:0px" cellpadding="0" cellspacing="0">
  <tr><td rowspan=2><a href="/"> <img alt="Dargens" height=60 src="/images/logon.jpg" /></a></td>
    <td align="left">
        <input maxlength="2048" id="q" name="q" size="55" title="Dargens Search" value="<%=params[:q]%>">
    </td>
    <td>
    <input type=submit value="Search" /><td><font size="-1">&nbsp;&nbsp;<span id='lpanel'><a href=http://localhost:54321/webgui/adddir onclick='return adddir();'>add shared directory</a></span></font></td>
    </td></tr>
    <tr>
    <td align="left" colspan=2><INPUT type="CHECKBOX"  name="content" id="content" value="on" <%=params[:content]=="on"?"CHECKED":""%> >
content
      <% link_to_remote 'query by string',{:url=>{:host=>"127.0.0.1:54321",:controller=>"webgui",:action =>"search",:only_path=>false},:update=>"result",:complete=>"queryed=1;",:with=>"'query='+$('query')"}%>
<INPUT type="radio" id="c1" name="catelog" value="commit_string" <%=params[:catelog]!="commit_hash"?"CHECKED":""%>>query by string!<INPUT type="radio" name="catelog" value="commit_hash" id="c2" <%=params[:catelog]=="commit_hash"?"CHECKED":""%>>query by hashlink!
        </td><td>&nbsp;</td>
  </tr>
</table>
    </form>
<table>
<tr><TH width='500px'><B><font size=4>Search Results:</font></B></TH><TH><B><font size=4>Downloading</font></B></TH></tr>
<tr><TD valign="top"><div id="qres"></div></TD><TD valign="top"><div id="dres"></div></TD></tr>
</table>


</body>
</html>
